package 语法.面向对象.元编程.Test

class T1 {
    public static void main(String[] args) {
        A.metaClass."aAndb" = { -> println 'a and b' }
        def a = new A()
        a.aAndb()
        def b = new B()
        b.aAndb()


        //------------------------------------------------------------
        ExpandoMetaClass.enableGlobally()
        List.metaClass.reversed = {
            def rl = []
            for (int i in (delegate.size() - 1..0)) {
                rl << delegate.getAt(i)
            }
            rl
        }
        def list = [1, 2, 3]
        list = list.reversed()
        println list
    }
}
